// DlgRotateBlock.cpp : implementation file
//

#include "stdafx.h"
#include "MotionControlSoftware.h"
#include "DlgRotateBlock.h"
#include "afxdialogex.h"


// CDlgRotateBlock dialog

IMPLEMENT_DYNAMIC(CDlgRotateBlock, CDialogEx)

CDlgRotateBlock::CDlgRotateBlock(CWnd* pParent /*=NULL*/)
	: CDialogEx(CDlgRotateBlock::IDD, pParent)
	, m_RotateAngle(0)
{
	m_pDoc = NULL;
}

CDlgRotateBlock::~CDlgRotateBlock()
{
}

void CDlgRotateBlock::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT_Rotate, m_RotateAngle);
}


BEGIN_MESSAGE_MAP(CDlgRotateBlock, CDialogEx)
	ON_BN_CLICKED(IDOK, &CDlgRotateBlock::OnBnClickedOk)
END_MESSAGE_MAP()


// CDlgRotateBlock message handlers


void CDlgRotateBlock::OnBnClickedOk()
{
	// TODO: Add your control notification handler code here
	if (m_pDoc != NULL)
	{
		if (UpdateData())
		{
			CRectEx rect;
			if (((CButton*)(GetDlgItem(IDC_CHECK_SingleRotate)))->GetCheck())
			{
				for (int i=0; i<m_pDoc->m_graphSelectedList.GetCount();i++)
				{
					CBlock* pCurBlock = (CBlock*)(m_pDoc->m_graphSelectedList[i]);
					pCurBlock->RotateGraph(pCurBlock->m_cRRect.GetCenterPt(),-m_RotateAngle);
				}
			}
			else
			{
				for (int i=0; i<m_pDoc->m_graphSelectedList.GetCount();i++)
				{
					CBlock* pCurBlock = (CBlock*)(m_pDoc->m_graphSelectedList[i]);
					rect.UnionRect(&pCurBlock->m_cRRect);
				}

				for (int i=0; i<m_pDoc->m_graphSelectedList.GetCount();i++)
				{
					CBlock* pCurBlock = (CBlock*)(m_pDoc->m_graphSelectedList[i]);
					pCurBlock->RotateGraph(rect.GetCenterPt(),-m_RotateAngle);
				}
			}
			m_pDoc->UpdateView();
		}
	}
}
